function [alpha_k, x_kk, fun_kk, grad_kk, norm_grad_kk, extra_kk] = ...
    Backtracking(n_dt_iter, x_k, fun, fun_k, p_k, verbose)
% [alpha_k, x_kk, fun_kk, grad_kk, norm_grad_kk, extra_kk] = ...
%    Backtracking(n_alpha_iter, x_k, fun, fun_k, p_k, verbose)
% 
% Backtracking performs Armijo backtracking line search [1, p. 41]
% for an optization algorithm.
%
% [1] J. Nocedal and S. J. Wright, 
%     Numerical Optimization, 
%     New York: Springer, 2000
%
% See also: L_BFGS
%
% 2013-07-25 --------------------------------------------------------------
% 
% Matthias J. Ehrhardt
% CMIC, University College London, UK
% 
% matthias.ehrhardt.11@ucl.ac.uk
% 
% -------------------------------------------------------------------------
        
    for m = 1 : n_dt_iter
        alpha_k = 3^(1-m);
        
        x_kk = x_k + alpha_k * p_k;        
        [fun_kk, grad_kk, norm_grad_kk, extra_kk] = fun(x_kk);
        
        if verbose
            fprintf('      %s: iter=%02i, fun_m=%5.8e, fun_0 - fun_m=%5.8e\n', Function_name, m, fun_kk, fun_k-fun_kk);
        end
        
        if fun_kk <= fun_k
            return
        end
    end
end